package org.footballmanager.pandafootball.system.controller;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.form.impl.FootSociatyBfinfoSearchForm;
import org.footballmanager.pandafootball.system.service.FootSociatyBfinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@SessionAttributes("footSociatyBfinfoSearchForm")
@RequestMapping("/foot/footSociatyBfinfo")
public class FootSociatyBfinfoController extends BaseController {
    /* 实体名称 */
    private static final String ENTITYNAME = "footSociatyBfinfo";
    private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.FOOT, ENTITYNAME);
    private static final String VIEWPAGE = String.format(Constants.VIEWPAGE, Constants.FOOT, ENTITYNAME);
    private static final String REDIRECT = String.format(Constants.REDIRECT, Constants.FOOT, ENTITYNAME);

    @Autowired
    private FootSociatyBfinfoService footSociatyBfinfoService;

    /**
     * 初始化
     *
     * @param map                         参数
     * @param footSociatyBfinfoSearchForm 条件参数
     */
    @ModelAttribute
    public void init(Model map, @ModelAttribute FootSociatyBfinfoSearchForm footSociatyBfinfoSearchForm) {
        FootSociatyBfinfoSearchForm newFootSociatyBfinfoSearchForm = new FootSociatyBfinfoSearchForm();
        if (footSociatyBfinfoSearchForm != null) {
            newFootSociatyBfinfoSearchForm = footSociatyBfinfoSearchForm;
        }
        map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), newFootSociatyBfinfoSearchForm);
    }

    /**
     * 战队报分列表
     *
     * @param map                         参数
     * @param footSociatyBfinfoSearchForm 条件
     * @return 页面
     */
    @RequestMapping(value = "/search")
    public String search(Model map, @ModelAttribute FootSociatyBfinfoSearchForm footSociatyBfinfoSearchForm) {
        footSociatyBfinfoService.search(ENTITYNAME, map, footSociatyBfinfoSearchForm);
        return LISTPAGE;
    }

    /**
     * 删除战队报分记录
     *
     * @param id      主键
     * @param request 请求
     * @return 页面
     */
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public String delete(@RequestParam Long id, HttpServletRequest request) {
        footSociatyBfinfoService.delete(id, request);
        return REDIRECT;
    }

    /**
     * 删除战队报分列表
     *
     * @param request                     请求
     * @param footSociatyBfinfoSearchForm 条件
     * @return 页面
     */
    @RequestMapping(value = "/deleteall", method = RequestMethod.POST)
    public String deleteall(HttpServletRequest request, @ModelAttribute FootSociatyBfinfoSearchForm footSociatyBfinfoSearchForm) {
        footSociatyBfinfoService.deleteAll(footSociatyBfinfoSearchForm, request);
        return REDIRECT;
    }

    /**
     * 浏览战队报分页面
     *
     * @param map                         参数
     * @param id                          主键
     * @param footSociatyBfinfoSearchForm 条件
     * @return 页面
     */
    @RequestMapping(value = "/view", method = RequestMethod.GET)
    public String openViewPage(Model map, @RequestParam Long id, @ModelAttribute FootSociatyBfinfoSearchForm footSociatyBfinfoSearchForm) {
        map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), footSociatyBfinfoSearchForm);
        map.addAttribute(ENTITYNAME, footSociatyBfinfoService.get(id));
        return VIEWPAGE;
    }

}
